"""
员工管理模块 接口对象层
"""
import requests



class IhrmEmpCURD(object):
    # 添加员工
    @classmethod
    def add_emp(cls, header, json_data):
        url = "http://ihrm-java.itheima.net/api/sys/user"
        resp = requests.post(url=url, headers=header, json=json_data)
        return resp

    # 查询员工
    @classmethod
    def query_emp(cls, emp_id, header):
        url = "http://ihrm-java.itheima.net/api/sys/user/" + emp_id
        resp = requests.get(url=url, headers=header)
        return resp

    # 修改员工
    @classmethod
    def modify_emp(cls, emp_id, header, modify_data):
        url = "http://ihrm-java.itheima.net/api/sys/user/" + emp_id
        resp = requests.put(url=url, headers=header, json=modify_data)
        return resp

    # 删除员工
    @classmethod
    def del_emp(cls, emp_id, header):
        url = "http://ihrm-java.itheima.net/api/sys/user/" + emp_id
        resp = requests.delete(url=url, headers=header)
        return resp


if __name__ == '__main__':
    header = {"Content-Type": "application/json", "Authorization": "Bearer 02559532-0aa2-4de9-92b6-984e552b51d6"}
    data_add = {
        "username": "业务猪001",
        "mobile": "13978738526",
        "workNumber": "9527"
    }
    # resp = IhrmEmpCURD.add_emp(header, data_add)
    # print("添加：", resp.json())

    emp_id = "1537286917396168704"
    resp = IhrmEmpCURD.query_emp(emp_id,header)
    print("查询：", resp.json())

    data = {"username":"撸管大神"}
    resp = IhrmEmpCURD.modify_emp(emp_id,header,data)
    print("修改：", resp.json())

    resp = IhrmEmpCURD.del_emp(emp_id,header)
    print("删除：", resp.json())
